package com.kede.api.file.controller;

import com.kede.api.file.domain.ResourceFileDomain;
import com.kede.api.file.service.ResourceFileService;
import com.kede.api.file.service.impl.ResourceFileServiceImpl;
import com.kede.api.file.utils.FileUtil;
import com.kede.dictenum.BoolDictEnum;
import com.kede.dictenum.ResourceFunDictEnum;
import com.kede.pojo.ResHttp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 文件服务
 **/
@RestController
@RequestMapping("file")
@Slf4j
public class FileController {


    @Resource
    private ResourceFileService resourceFileService;

    /**
     * 上传文件
     * @param uploadFiles
     * @param request
     * @return
     */
    @PostMapping("upload")
    public ResHttp upload(MultipartFile[] uploadFiles, HttpServletRequest request ){
        try {
            List<String> list = resourceFileService.upload(uploadFiles);
            return ResHttp.okData(list);
        }catch (Exception e){
            return ResHttp.failMsg(e.getMessage());
        }
    }


    /**
     * wang编辑器的上传方法
     *
     * @param uploadFiles 上传文件
     * @param hrefPrefix  href前缀
     * @return {@link ResourceFileServiceImpl.WangEditorUploadRes}
     */
    @PostMapping("wangEditorUpload")
    public ResourceFileServiceImpl.WangEditorUploadRes wangEditorUpload(MultipartFile[] uploadFiles, String  hrefPrefix){
        return resourceFileService.wangEditorUpload(uploadFiles,hrefPrefix);
    }

}
